<template>
  <div class="home-page" :style="{ backgroundImage: `url(${pageBackground})`, backgroundSize: 'cover', backgroundPosition: 'center' }">
    <Navbar />

    <!-- 用户信息按钮 (User Info Button) -->
    <el-button type="info" @click="navigateTo('user')" class="user-info-button">
      <i class="el-icon-user"></i> 用户信息
    </el-button>

    <!-- 英雄区 (Hero Section) -->
    <section class="hero-section">
      <div class="hero-content">
        <h1>欢迎使用惊喜一餐！</h1>
        <p>发现附近最好的餐厅，享受美味佳肴。</p>
        <el-button type="primary" @click="navigateTo('restaurant-list')" class="hero-button">查找餐厅</el-button>
      </div>
    </section>

    <!-- 推荐餐厅区 (Recommended Restaurants Section) -->
    <section class="recommended-restaurants">
      <div class="section-title">
        <h2>为您推荐</h2>
        <el-divider />
      </div>
      <el-row :gutter="20" class="restaurant-grid">
        <el-col :span="6" v-for="(restaurant, index) in recommendedRestaurants" :key="index" class="restaurant-card-wrapper">
          <el-card shadow="hover" @click="navigateToRestaurant(restaurant.id)" class="restaurant-card">
            <div class="restaurant-image-container">
              <img :src="restaurant.image" alt="餐厅图片" class="restaurant-image">
            </div>
            <div class="restaurant-info">
              <h3>{{ restaurant.name }}</h3>
              <p>{{ restaurant.address }}</p>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </section>

    <!-- 底部导航 (Footer Navigation) -->
    <footer class="footer">
      <el-row :gutter="20" class="footer-links">
        <el-col :span="6" :offset="9">
          <el-button type="text" @click="navigateTo('restaurant-list')">查找餐厅</el-button>
        </el-col>
        <el-col :span="6">
          <el-button type="text" @click="navigateTo('user')">用户信息</el-button>
        </el-col>
      </el-row>
    </footer>
  </div>
</template>

<script>
import { ref } from 'vue';
import { useRouter } from 'vue-router';

export default {
  setup() {
    const router = useRouter();
    const pageBackground = 'https://img1.baidu.com/it/u=3694467961,2120749926&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=1000'; // 首页背景图片

    const recommendedRestaurants = ref([
      { id: 1, name: '美食天堂', address: '市中心商业区', image: 'https://img1.baidu.com/it/u=3694467961,2120749926&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=1000' },
      { id: 2, name: '星空小屋', address: '郊区公园旁', image: 'https://img0.baidu.com/it/u=2587508774,2092054243&fm=253&fmt=auto&app=120&f=JPEG?w=749&h=500' },
      { id: 3, name: '湖畔餐厅', address: '湖边风景区', image: 'https://img2.baidu.com/it/u=3073678029,2769107&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500' }
    ]);

    const navigateTo = (path) => {
      router.push({ name: path });
    };

    const navigateToRestaurant = (id) => {
      router.push({ name: 'restaurant-detail', params: { id } });
    };

    return {
      pageBackground,
      recommendedRestaurants,
      navigateTo,
      navigateToRestaurant
    };
  }
};
</script>

<style scoped>
.home-page {
  text-align: center;
  padding-bottom: 40px;
  position: relative; /* 确保用户信息按钮可以相对于首页进行绝对定位 */
  min-height: 100vh; /* 确保背景覆盖整个页面 */
  color: #fff; /* 文本颜色适应深色背景 */
}

/* 用户信息按钮 (User Info Button) */
.user-info-button {
  position: absolute;
  top: 20px;
  right: 20px;
  font-size: 1rem;
  padding: 10px 20px;
  border-radius: 20px;
  background-color: rgba(255, 255, 255, 0.8); /* 半透明白色背景 */
  border-color: rgba(255, 255, 255, 0.8);
  color: #000; /* 黑色文本 */
  transition: all 0.3s ease;
  z-index: 10; /* 确保按钮在其他元素之上 */
}

.user-info-button:hover {
  background-color: rgba(255, 255, 255, 1);
  border-color: rgba(255, 255, 255, 1);
  transform: scale(1.05);
}

.user-info-button i {
  margin-right: 5px;
}

.hero-section {
  padding: 80px 0;
  background: rgba(0, 0, 0, 0.5); /* 半透明黑色背景 */
  color: #fff;
  position: relative;
}

.hero-content {
  max-width: 800px;
  margin: 0 auto;
  text-align: center;
}

.hero-content h1 {
  font-size: 3rem;
  margin-bottom: 20px;
}

.hero-content p {
  font-size: 1.2rem;
  margin-bottom: 30px;
}

.hero-button {
  font-size: 1.1rem;
  padding: 12px 30px;
  margin: 0 10px;
  transition: all 0.3s ease;
}

.hero-button:hover {
  transform: scale(1.05);
}

.recommended-restaurants {
  padding: 40px 20px;
  background: rgba(255, 255, 255, 0.8); /* 半透明白色背景 */
  color: #000; /* 黑色文本 */
}

.section-title {
  margin-bottom: 40px;
  text-align: center;
}

.section-title h2 {
  font-size: 2rem;
  margin-bottom: 10px;
}

.restaurant-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
}

.restaurant-card-wrapper {
  margin-bottom: 20px;
  width: 100%;
  max-width: 300px;
}

.restaurant-card {
  cursor: pointer;
  transition: transform 0.3s ease;
  background: rgba(255, 255, 255, 0.9); /* 半透明白色背景 */
  border-radius: 10px;
  overflow: hidden;
}

.restaurant-card:hover {
  transform: translateY(-10px);
}

.restaurant-image-container {
  height: 200px; /* 固定高度 */
  overflow: hidden;
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
}

.restaurant-image {
  width: 100%;
  height: 100%;
  object-fit: cover; /* 确保图片填充容器并保持比例 */
}

.restaurant-info {
  padding: 10px;
  text-align: left;
}

.restaurant-info h3 {
  margin-bottom: 5px;
}

.restaurant-info p {
  font-size: 0.9rem;
  color: #666;
}

.footer {
  padding: 20px 0;
  background: rgba(255, 255, 255, 0.8); /* 半透明白色背景 */
  margin-top: 40px;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
  color: #000; /* 黑色文本 */
}

.footer-links {
  text-align: center;
}

.footer-links .el-button {
  font-size: 1rem;
  color: #409EFF;
  transition: color 0.3s ease;
}

.footer-links .el-button:hover {
  color: #66b1ff;
}

@media (max-width: 768px) {
  .hero-content h1 {
    font-size: 2rem;
  }

  .hero-content p {
    font-size: 1rem;
  }

  .hero-button {
    font-size: 1rem;
    padding: 10px 20px;
  }

  .restaurant-card-wrapper {
    width: 100%;
    margin-bottom: 20px;
  }

  .footer-links {
    flex-direction: column;
  }

  .footer-links .el-col {
    margin-bottom: 10px;
  }
}
</style>